package cn.tx.config;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Mxb
 * @version 1.0
 * @date 2020/10/15 21:40
 */
@Component
@RabbitListener(queues = {"new.queue"})
public class MessageReceive5 {
    @RabbitHandler
    public void onMessage(String content, Message message, Channel channel) {
        System.out.println("来到了新的世界，正在消费中。。。");
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        try {
            channel.basicAck(deliveryTag, false);
            System.out.println("签收成功：" + content);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println("签收成功时间:" + sdf.format(new Date()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
